/*******************************************************************************

ATTENTION, this is an altered version of the xhtml_gen library, specifically tailored to libwebconf's needs please refer to the original library

xhtml_gen: xhtml generation library.
Copyright (c) 2006  Mitchel Haas

This software is provided 'as-is', without any express or implied warranty. 
In no event will the author be held liable for any damages arising from 
the use of this software.

Permission is granted to anyone to use this software for any purpose, 
including commercial applications, and to alter it and redistribute it freely, 
subject to the following restrictions:

1.	The origin of this software must not be misrepresented; 
you must not claim that you wrote the original software. 
If you use this software in a product, an acknowledgment in the product 
documentation would be appreciated but is not required.

2.	Altered source versions must be plainly marked as such, 
and must not be misrepresented as being the original software.

3.	The above copyright notice and this permission notice may not be removed 
or altered from any source distribution.

For complete documentation on this library, see http://www.datasoftsolutions.net
Email questions, comments or suggestions to mhaas@datasoftsolutions.net
*******************************************************************************/
#pragma once
#include "basic_tree.hpp"
#include "content.hpp"
#include "xhtml_def.hpp"
#include "content.hpp"
#include "pc_data.hpp"
#include "tag.hpp"
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <stdexcept>

namespace xhtml_gen
{
// forward declarations
class xhtml_doc;

class xhtml_element : public basic_tree<content, xhtml_element, std::vector<xhtml_element*> >
{
public:
	// typedefs
	typedef std::vector<xhtml_element*> container_type;
	typedef basic_tree<content, xhtml_element, container_type> basic_tree_type;
	friend class basic_tree<content, xhtml_element, container_type>;
	friend class xhtml_doc;

	// constructors/destructor
	explicit xhtml_element(xhtml_strict _tag, const std::string& _id = "", const std::string& _class = "");
	xhtml_element(const xhtml_element& src);  // copy constructor
	virtual ~xhtml_element() { basic_tree_type::clear(); }
	xhtml_element();
private:
	explicit xhtml_element(const content& _content);

public:
	// operators
	xhtml_element& operator = (const xhtml_element& rhs);
	xhtml_element& operator [](const int index);
	const xhtml_element& operator [](const int index) const;

	// public interface
	std::string get_xhtml(const int indent = 0) const;
	bool set_attribute( const attribute _attribute, const std::string& value );
	bool set_style( const css_property _property, const std::string& value );
	std::string get_attribute( const attribute _attribute ) const;
	std::string get_style( const css_property _property ) const;
	nesting_type get_nesting_type() const;
	xhtml_element::iterator insert(const std::string& _pc_data);
	xhtml_element::iterator insert(const xhtml_element& elem);
	xhtml_element::iterator insert(xhtml_element::const_iterator pos, const std::string& _pc_data);
	xhtml_element::iterator insert(xhtml_element::const_iterator pos, const xhtml_element& elem);
	xhtml_element& operator << (const std::string& pc_data);
	xhtml_element& operator << (const xhtml_element& elem);

private:
	void set_clone_function();
	void set(const xhtml_element& elem) { basic_tree_type::set(elem, this); }
	void set(const content& stored_obj) { basic_tree_type::set(stored_obj); }
	basic_tree_type::iterator insert(const content& content_obj ) { return basic_tree_type::insert(content_obj, this); }
	const content* get() const { return basic_tree_type::get(); }
	content* get() { return basic_tree_type::get(); }
	xhtml_element::iterator insert(xhtml_element::const_iterator pos, const content& _content);

};

typedef xhtml_element element;
}

